package com.dwj.auto.comment;

import com.dwj.auto.comment.service.IAutoCommentService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Slf4j
@ServletComponentScan
@SpringBootApplication
@MapperScan("com.dwj.auto.comment.dao.mapper")
public class AutoCommentApplication implements ApplicationRunner {

    @Autowired
    private IAutoCommentService autoCommentService;

    public static void main(String[] args) {
        SpringApplication.run(AutoCommentApplication.class, args);
    }

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("Project is running, loading comment data...");
        long start = System.currentTimeMillis();
        autoCommentService.initCommentData();
        long end = System.currentTimeMillis();
        log.info("comment data is load! completed in " + (end - start) + " ms ");
    }
}
